<template>
  <div class="mall-list-constainer">
    <ul>
      <li v-for="item in list" :key="item.itemId">
        <el-popover placement="top">
          <p>确定删除吗？</p>
          <div style="text-align:right;margin: 10px 0 0">
            <el-button
              type="primary"
              size="mini"
              @click="deleteCollect(item.itemId)"
              >确定</el-button
            >
          </div>
          <i
            class="el-icon-close delete"
            slot="reference"
            v-show="isDelete"
          ></i>
        </el-popover>
        <router-link :to="{ path: '/item/details', query: { id: item.id } }">
          <img :src="item.imageUrl ? getImageUrl(item.imageUrl) : 'https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png'" alt />
          <h2>{{ item.name }}</h2>
          <h3>{{ item.title }}</h3>
          <p>
            <span>{{ item.price }}元</span>
            <span v-show="item.price != item.salePrice" class="del"
              >{{ item.salePrice }}元</span
            >
          </p>
        </router-link>
      </li>
      <li v-show="isMore && list.length >= 1" class="list-more">
        <router-link :to="{ path: '/item', query: { typeId: typeId } }">
          浏览更多
          <i class="el-icon-d-arrow-right"></i>
        </router-link>
      </li>
    </ul>
  </div>
</template>
<script>
import { mixin } from '../mixins'
export default {
  mixins: [mixin],
  props: ['list', 'isMore', 'isDelete'],
  data() {
    return {}
  },
  computed: {
    // 通过list获取当前显示的商品的分类ID，用于“浏览更多”链接的参数
    typeId: function () {
      const typeId = []
      if (this.list !== '') {
        for (let i = 0; i < this.list.length; i++) {
          const id = this.list[i].typeId
          if (!typeId.includes(id)) {
            typeId.push(id)
          }
        }
      }
      return typeId
    }
  }
}
</script>
<style scoped>
.mall-list-constainer ul {
  display: grid;
  grid-template-columns: repeat(auto-fill, 234px);
  grid-column-gap: 13.76px;
}
.mall-list-constainer ul li {
  z-index: 1;
  width: 234px;
  height: 280px;
  padding: 10px 0;
  margin-bottom: 15px;
  background-color: white;
  -webkit-transition: all 0.2s linear;
  transition: all 0.2s linear;
}
.mall-list-constainer ul li:hover {
  z-index: 2;
  -webkit-box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
  -webkit-transform: translate3d(0, -2px, 0);
  transform: translate3d(0, -2px, 0);
}
.mall-list-constainer ul li img {
  width: 160px;
  height: 160px;
  display: block;
  margin: 0 auto;
}
.mall-list-constainer ul li h2 {
  margin: 25px 10px 0;
  font-size: 14px;
  font-weight: 400;
  color: #333;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.mall-list-constainer ul li h3 {
  margin: 5px 10px;
  height: 18px;
  font-size: 12px;
  font-weight: 400;
  color: #b0b0b0;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.mall-list-constainer ul li p {
  margin: 10px 10px 10px;
  text-align: center;
  color: #ff6700;
}
.mall-list-constainer ul li p .del {
  margin-left: 0.5em;
  color: #b0b0b0;
  text-decoration: line-through;
}
.mall-list-constainer .list-more {
  text-align: center;
  line-height: 280px;
}
.mall-list-constainer .list-more a {
  font-size: 18px;
  color: #333;
}
.mall-list-constainer .list-more a:hover {
  color: #ff6700;
}
.mall-list-constainer ul li .delete {
  position: absolute;
  top: 10px;
  right: 10px;
  display: none;
}
.mall-list-constainer ul li:hover .delete {
  display: block;
}
.mall-list-constainer ul li .delete:hover {
  color: #ff6700;
}
</style>
